//
//  GroupNoticeVC.m
//  wanzhaoIM
//
//  Created by liuyuantao on 15/6/1.
//  Copyright (c) 2015年 liuyuantao. All rights reserved.
//

#import "GroupNoticeVC.h"
#import "MicroDef.h"
#import "CHSCharacterCountTextView.h"
#import "CGroupMgr.h"

#import "CXmppMgr.h"
@interface GroupNoticeVC ()
{
    CHSCharacterCountTextView *_textView;
}
@end

@implementation GroupNoticeVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:K_XMPPUPDATEGROUPINFO object:nil];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
    [self.navigationController setNavigationBarHidden:NO];
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationItem setNewTitleCenter:@"公告详情"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateGroup) name:K_XMPPUPDATEGROUPINFO object:nil];
    
    self.group = [[[CGroupMgr alloc] init] loadGroup:self.group.GroupId];
    if (self.group.GroupNotice.length > 0) {
        CHSCharacterCountTextView *textView = [[CHSCharacterCountTextView alloc] init];
        _textView = textView;
        textView.layer.borderWidth = 0.5f;
        textView.layer.borderColor = RGBCOLOR(0xd4, 0xd4, 0xd4).CGColor;
        textView.layer.cornerRadius = 2.5f;
        textView.backgroundColor = [UIColor whiteColor];
        //    _textView.userInteractionEnabled = YES;
        [textView setText:self.group.GroupNotice];
        [textView setEditEnable:NO];
        [self.view addSubview:textView];
        UIView *superView = self.view;
        
        CGFloat padding  = 10.0f;
        CGFloat padding1 = 15.0f;
        textView.frame = CGRectMake(padding1, padding, HARDWARE_SCREEN_WIDTH - 2 * padding1, HARDWARE_SCREEN_HEIGHT - 64.0f - 2 * padding);
       
    } else {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"暂时没有群公告" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"loginErrorImage"] forState:UIControlStateNormal];
        button.backgroundColor = ClearColor;
        [button setTitleColor:RGBCOLOR(0x64, 0x64, 0x64) forState:UIControlStateNormal];
        button.userInteractionEnabled = NO;
        button.titleLabel.font = [UIFont systemFontOfSize:14.0f];
        [self.view addSubview:button];
        UIView *superView = self.view;
        
        
        button.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64.0f);
        
    }
    
}

- (void)updateGroup
{
    self.group = [[[CGroupMgr alloc] init] loadGroup:self.group.GroupId];
    [_textView setText:self.group.GroupNotice];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
